﻿
// ProjectAADlg.cpp: 实现文件
//

#include "pch.h"
#include "framework.h"
#include "ProjectAA.h"
#include "ProjectAADlg.h"
#include "afxdialogex.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

//ImgCap *imgCap;
//ImgFile imgFile; 
//CTS CTSCam;

// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialogEx
{
public:
	CAboutDlg();

	// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum
	{
		IDD = IDD_ABOUTBOX
	};
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	// 实现
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// CProjectAADlg 对话框



CProjectAADlg::CProjectAADlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_PROJECTAA_DIALOG, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CProjectAADlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_BUTTON_START, m_butStart);
	DDX_Control(pDX, IDC_BUTTON_STOP, m_butStop);
	DDX_Control(pDX, IDC_BUTTON_SAVE, m_butSave);
	DDX_Control(pDX, IDC_STATIC_3, m_static_3);
	DDX_Control(pDX, IDC_STATIC_19, m_static_19);
	DDX_Control(pDX, IDC_STATIC_20, m_static_20);
	DDX_Control(pDX, IDC_STATIC_42, m_static_42);
	DDX_Control(pDX, IDC_STATIC_61, Static1);
	DDX_Control(pDX, IDC_BUTTON_HOME_40, Button1);
	DDX_Control(pDX, IDC_CHECK1, Button2);
	DDX_Control(pDX, IDC_CHECK2, Button3);
	DDX_Control(pDX, IDC_STATIC_23, m_static_23);
}

BEGIN_MESSAGE_MAP(CProjectAADlg, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_32771, &CProjectAADlg::OnOpenLogDlg)
	ON_COMMAND(ID_32773, &CProjectAADlg::OnOpenMotorDlg)
	ON_BN_CLICKED(IDC_BUTTON1, &CProjectAADlg::OnBnClickedButton1)
	ON_COMMAND(ID_32772, &CProjectAADlg::OnOpenProjectDlg)
	ON_BN_CLICKED(IDC_BUTTON_START, &CProjectAADlg::OnBnClickedButtonStart)
	ON_BN_CLICKED(IDC_BUTTON_STOP, &CProjectAADlg::OnBnClickedButtonStop)
	ON_COMMAND(ID_32776, &CProjectAADlg::OnOpenCaptureDlg)
	ON_COMMAND(ID_32777, &CProjectAADlg::OnOpenSFRDlg)
	ON_WM_SIZE()
	ON_COMMAND(ID_32774, &CProjectAADlg::OnOpenTcpipDlg)
	ON_MESSAGE(WM_SEND_SOCKET_SERVER_MSG_TO_MAIN_UI, &CProjectAADlg::OnReceiveServerMsg)
	ON_COMMAND(ID_32778, &CProjectAADlg::OnOpenIODlg)
	ON_BN_CLICKED(IDC_CHECK1, &CProjectAADlg::OnBnClickedCheck1)
	ON_BN_CLICKED(IDC_CHECK2, &CProjectAADlg::OnBnClickedCheck2)
	ON_WM_CTLCOLOR()
	ON_COMMAND(ID_32775, &CProjectAADlg::OnOpenAADlg)
	//	ON_WM_DRAWITEM()
	ON_BN_CLICKED(IDC_BUTTON_HOME_40, &CProjectAADlg::OnBnClickedButtonHome40)
	ON_COMMAND(ID_32782, &CProjectAADlg::OnOpenManualControl)
	ON_COMMAND(ID_32781, &CProjectAADlg::OnOpenComDlg)
	ON_COMMAND(ID_32780, &CProjectAADlg::OnOpenLogin)
	ON_BN_CLICKED(IDC_BUTTON_SAVE, &CProjectAADlg::OnBnClickedButtonSave)
	ON_BN_CLICKED(IDC_BUTTON_CLEAR1, &CProjectAADlg::OnBnClickedButtonClear1)
	ON_BN_CLICKED(IDC_BUTTON_CLAER2, &CProjectAADlg::OnBnClickedButtonClaer2)
	ON_BN_CLICKED(IDC_BUTTON2, &CProjectAADlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON_HOME_41, &CProjectAADlg::OnBnClickedButtonHome41)
	ON_BN_CLICKED(IDC_BUTTON3, &CProjectAADlg::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON4, &CProjectAADlg::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON_RESET_TZ, &CProjectAADlg::OnBnClickedButtonResetTz)
	ON_BN_CLICKED(IDC_BUTTON5, &CProjectAADlg::OnBnClickedButton5)
END_MESSAGE_MAP()


// CProjectAADlg 消息处理程序

BOOL CProjectAADlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	unique_mutex = CreateMutex(NULL, FALSE, L"ProjectAA");
	DWORD errCode = GetLastError();
	if (errCode == ERROR_ALREADY_EXISTS) {
		Sleep(500);
		CloseHandle(unique_mutex);
		MessageBox(L"AA软件已经被打开!", L"Warning", 0);
		::TerminateProcess(::GetCurrentProcess(), NULL);//终止原先程序
	}

	gSystemMgr.GeneralSettingIniInit();//读取型号配置

	CString cstr;
	cstr.Format(L"... 当前型号:%s ...\r\n\r\n请优先点检设备硬件", gSystemMgr.m_sGeneralSetting.m_cstrProjectName);
	AfxMessageBox(cstr.GetBuffer(), MB_OK | MB_SYSTEMMODAL);


	// 设置字体参数
	gSystemMgr.m_editFont.CreateFont(32, 0, 4, 0, FW_NORMAL, FALSE, FALSE, 0,
		ANSI_CHARSET,
		OUT_DEFAULT_PRECIS,
		CLIP_DEFAULT_PRECIS,
		DEFAULT_QUALITY,
		DEFAULT_PITCH | FF_SWISS,
		_T("Arial"));
	m_static_3.SetFont(&gSystemMgr.m_editFont);
	m_static_3.SetWindowTextW(L"等待");
	m_static_19.SetFont(&gSystemMgr.m_editFont);
	m_static_19.SetWindowTextW(L"...");
	m_static_20.SetFont(&gSystemMgr.m_editFont);
	m_static_20.SetWindowTextW(L"等待");
	m_static_23.SetFont(&gSystemMgr.m_editFont);
	m_static_23.SetWindowTextW(L"等待");
	m_static_42.SetFont(&gSystemMgr.m_editFont);
	m_static_42.SetWindowTextW(L"...");
	Static1.SetFont(&gSystemMgr.m_editFont);
	Button1.SetFont(&gSystemMgr.m_editFont);
	Button2.SetFont(&gSystemMgr.m_editFont);
	Button3.SetFont(&gSystemMgr.m_editFont);

	//轴的比率尺
	gSystemMgr.m_vCMotor[MOTOR_X].PositionRatio = 5000;//3		-1000 * 5 = 1r			1r = 1mm
	gSystemMgr.m_vCMotor[MOTOR_Y].PositionRatio = 5000;//3		-1000 * 5 = 1r			1r = 1mm
	gSystemMgr.m_vCMotor[MOTOR_Z].PositionRatio = 5000.0;//3		-1000 * 5 = 1r		1r = 1mm
	gSystemMgr.m_vCMotor[MOTOR_Xt].PositionRatio = 7462.686;//1000*5.1=1r		7462.686567
	gSystemMgr.m_vCMotor[MOTOR_Yt].PositionRatio = 10000;//1000*10=1r

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != nullptr)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。  当应用程序主窗口不是对话框时，框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标


	m_menu.LoadMenuW(IDR_MENU1);
	this->SetMenu(&m_menu);

	SetUiHandle();

	gSystemMgr.CaptureConfigIniInit();//采图配置
	gSystemMgr.AAConfigIniInit();//AA运动配置
	gSystemMgr.TcpipConfigIniInit();//Tcpip通讯配置
	gSystemMgr.RS232ConfigIniInit();//RS232通讯配置
	gSystemMgr.LoginConfigIniInit();//Login信息
	gSystemMgr.StateConfigIniInit();//统计信息
	gSystemMgr.ReadErrorListIni();//报错信息

	gSystemMgr.m_ptrMainUI = this;

	if (m_cLogDlg == nullptr)
	{
		m_cLogDlg = new CLogDlg;
		m_cLogDlg->Create(IDD_DIALOG_LOG, this);
	}
	m_cLogDlg->ShowWindow(SW_HIDE);

	bool bInit = gSystemMgr.DMC3800Init();//轴卡初始化
	if (bInit)
	{
		//gSystemMgr.MotorInit();//轴配置
		gSystemMgr.MotorReadConfig();

		//gSystemMgr.StartCheckCanLinkThread();
		Sleep(100);
		//gSystemMgr.m_cIo.DMC_SetAllOutputOff();
		gSystemMgr.m_cIo.StartGetIoInputThread();

		gSystemMgr.StartGetMotorIoThread();//状态？
		gSystemMgr.StartGetMotorEncoderThread();//位置？
		//gSystemMgr.m_cIo.SetOutputIo(18, ON);
		Sleep(1000);
		gSystemMgr.m_cIo.SetOutputIo(20, ON);
	}

	switch (gSystemMgr.m_nImageSource)
	{
		case IMG_DEV_FILE:
			gSystemMgr.imgCap = (ImgCap*)&gSystemMgr.imgFile;
			//SendMessage(HWND_STATUS, SB_SETTEXT, 2, (LPARAM)"Image Files");
			break;
		case IMG_DEV_CTS:
			Cam_Init();
			gSystemMgr.m_bCTSInitFlag = 1;
			gSystemMgr.imgCap = (ImgCap*)&gSystemMgr.imgCTS;
			//SendMessage(HWND_STATUS, SB_SETTEXT, 2, (LPARAM)"CTS Cam");
			break;
		case IMG_RO_LONGO:
			gSystemMgr.imgCap = (ImgCap*)&gSystemMgr.imgRLG;
			//SendMessage(HWND_STATUS, SB_SETTEXT, 2, (LPARAM)"RLG Cam");
			break;
	}
	gSystemMgr.StartCaptureThread();
	gSystemMgr.StartImageTestThread();

	GetClientRect(&m_rcUiRect);

	if (!gSystemMgr.changeImg.init_lib())
	{
		//logdlg.log("convert init error");
		gSystemLog.DisplayLogAndSave(L"convert init error", LV_ERROR);
	}

	//Tcpip通信自动建立服务器 或 自动连接
	if (gSystemMgr.m_nModeSelect == 0 && gSystemMgr.m_bAutoFlag)
	{
		USES_CONVERSION;
		char* c_strIp = T2A(gSystemMgr.m_cstrIPAdd);
		bool bCreateServer = gSystemMgr.m_cSocketServer.OpenSocketServer(const_cast <char*> ("Server"), c_strIp, gSystemMgr.m_nPort);
		CString cstr;
		cstr.Format(L"Socket Server Build result:%d", bCreateServer);
		gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_ERROR);
		if (bCreateServer)
		{
			gSystemMgr.StartSocketAcceptClientThread();
		}
	}

	gSystemMgr.StartTcpipRelinkThread();
	gSystemMgr.StartAutoGlueThread();
	gSystemMgr.StartAutoAAThread();
	gSystemMgr.StartLightControlThread();
	gSystemMgr.StartScanButtonValueThread();
	gSystemMgr.StartOtherControlThread();
	gSystemMgr.StartRS232LinkThread();
	//gSystemMgr.StartPowerLinkThread();
	gSystemMgr.StartTimeCountThread();

	//画按钮
	CRect rect;
	m_butStart.GetWindowRect(rect);
	long width = rect.right - rect.left;
	long height = rect.bottom - rect.top;
	HICON hicon_btn = (HICON)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON_START), IMAGE_ICON, width - 30, height - 10, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION);
	m_butStart.SetIcon(hicon_btn);
	m_butStop.GetWindowRect(rect);
	width = rect.right - rect.left;
	height = rect.bottom - rect.top;
	hicon_btn = (HICON)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON_STOP), IMAGE_ICON, width - 30, height - 10, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION);
	m_butStop.SetIcon(hicon_btn);
	m_butSave.GetWindowRect(rect);
	width = rect.right - rect.left;
	height = rect.bottom - rect.top;
	hicon_btn = (HICON)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON_SAVE), IMAGE_ICON, width - 30, height - 10, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION);
	m_butSave.SetIcon(hicon_btn);

	CRect rcScreen;
	SystemParametersInfo(SPI_GETWORKAREA, 0, &rcScreen, 0);
	gSystemMgr.m_nCrtScreenWidth = rcScreen.Width() / 1;
	gSystemMgr.m_nCrtScreenHeight = rcScreen.Height() / 1;
	//::SetWindowPos(m_hWnd, HWND_TOP, gSystemMgr.m_nCrtScreenWidth * 0, gSystemMgr.m_nCrtScreenHeight * 0, gSystemMgr.m_nCrtScreenWidth, gSystemMgr.m_nCrtScreenHeight, SWP_SHOWWINDOW);

	//{
	//	if (m_cLoginDlg != nullptr)
	//	{
	//		m_cLoginDlg->ShowWindow(SW_SHOW);
	//	}
	//	if (m_cLoginDlg == nullptr)
	//	{
	//		m_cLoginDlg = new CLoginDlg;
	//		m_cLoginDlg->Create(IDD_DIALOG_LOGIN, this);
	//	}
	//	m_cLoginDlg->ShowWindow(SW_SHOW);
	//}

	ShowWindow(SW_MAXIMIZE);

	SetWindowText(L"STK L3 AAv1.1.9 [#T]");

	return TRUE;  // 除非将焦点设置到控件，否则返回 TRUE
}

void CProjectAADlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialogEx::OnSysCommand(nID, lParam);
	}
}

// 如果向对话框添加最小化按钮，则需要下面的代码
//  来绘制该图标。  对于使用文档/视图模型的 MFC 应用程序，
//  这将由框架自动完成。

void CProjectAADlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CRect rect;
		CPaintDC dc(this);
		GetClientRect(rect);
		dc.FillSolidRect(rect, RGB(169, 179, 195));//设置为绿色背景  

		CDialogEx::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CProjectAADlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CProjectAADlg::SetUiHandle()
{
	//m_menu.EnableMenuItem(ID_32781, MF_DISABLED);
	//m_menu.EnableMenuItem(ID_32774, MF_DISABLED);
	//m_menu.EnableMenuItem(ID_32773, MF_DISABLED);
	//m_menu.EnableMenuItem(ID_32778, MF_DISABLED);
	//m_menu.EnableMenuItem(ID_32782, MF_DISABLED);
	//m_menu.EnableMenuItem(ID_32776, MF_DISABLED);
	//m_menu.EnableMenuItem(ID_32777, MF_DISABLED);
	//m_menu.EnableMenuItem(ID_32775, MF_DISABLED);

}


void CProjectAADlg::OnOpenLogDlg()
{
	if (m_cLogDlg != nullptr)
	{
		m_cLogDlg->ShowWindow(SW_SHOW);
	}
	//else
	//{
	//	m_cLogDlg = new CLogDlg;
	//	m_cLogDlg->Create(IDD_DIALOG_LOG, this);
	//}
}


void CProjectAADlg::OnOpenMotorDlg()
{
	if (m_cMotorDlg != nullptr)
	{
		delete m_cMotorDlg;
		m_cMotorDlg = nullptr;
	}
	if (m_cMotorDlg == nullptr)
	{
		m_cMotorDlg = new CMotorDlg;
		m_cMotorDlg->Create(IDD_DIALOG_MOTOR, this);
	}
	m_cMotorDlg->ShowWindow(SW_SHOW);
}


void CProjectAADlg::OnBnClickedButton1()
{
	gSystemLog.DisplayLogAndSave(L"Test", LV_ERROR);



	std::thread t([&]() {

		int times = 10;
		while (times-- > 0)
		{
			Sleep(200);
			double fps = gSystemMgr.imgCap->GetFPS();

			CString str = L"";
			str.Format(L"FPS:%f", fps);
			gSystemLog.DisplayLogAndSave(str.GetBuffer(), LV_ERROR);
		}
		});
	t.detach();


	return;
	//CFileDialog dlg(TRUE, L"*.bmp;*.jpg;*.tif", NULL,
	//	OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY,
	//	L"图片(*.bmp;*.jpg;*.tif;*.png)|*.bmp;*.jpg;*.tif;*.png||", NULL);// 选项图片的约定;  
	//dlg.m_ofn.lpstrTitle = _T("打开图片");// 打开文件对话框的标题名;(*.bmp; *.jpg) |*.bmp; *.jpg | 

	//if (dlg.GetFileExt() != "bmp" && dlg.GetFileExt() != "jpg"&&dlg.GetFileExt() != "tif"&&dlg.GetFileExt() != "png")
	//{
	//	AfxMessageBox(_T("请选择正确的图片格式！"), MB_OK);
	//	return;
	//}
	//gSystemMgr.DrawSFRCurve(FFT_NUM / 2);
	//char sn[100];
	//sprintf(sn, "NOTREAD");
	//if(!strcmp(sn, "NOTREAD"))
	//	gSystemLog.DisplayLogAndSave(L"Test2", LV_ERROR);
	//else
	//	gSystemLog.DisplayLogAndSave(L"Dif2", LV_ERROR);
	//if (gSystemMgr.m_nLightMode == 4) {
	//	gSystemMgr.m_nLightMode = 0;
	//}
	//else
	//	gSystemMgr.m_nLightMode = 4;
	//gSystemMgr.m_nButtonValue = 11;
	vector < vector<double>> vdSfrValue;
	vector<double> vdSfrValue1;
	vector<double> vdSfrValue2;
	vector<double> vdSfrValue3;
	vector<double> vdSfrValue4;
	vector<double> vdSfrValue5;

	for (int z = 0; z < 30; z++)//50
	{
		gSystemMgr.m_nAAStepCnt++;
		for (int i = 0; i < SLANTED_BW_NUM; i++)
		{
			switch (i)
			{
				case 0:
					vdSfrValue1.push_back(50);
					break;
				case 1:
					vdSfrValue2.push_back(50);
					break;
				case 2:
					vdSfrValue3.push_back(50);
					break;
				case 3:
					vdSfrValue4.push_back(50);
					break;
				case 4:
					vdSfrValue5.push_back(50);
					break;
			}
		}

		vdSfrValue.clear();
		vdSfrValue.push_back(vdSfrValue1);
		vdSfrValue.push_back(vdSfrValue2);
		vdSfrValue.push_back(vdSfrValue3);
		vdSfrValue.push_back(vdSfrValue4);
		vdSfrValue.push_back(vdSfrValue5);
		gSystemMgr.DrawFocusCurve(vdSfrValue);

	}

}


void CProjectAADlg::OnOpenProjectDlg()
{
	if (m_cChangeProjectDlg != nullptr)
	{
		delete m_cChangeProjectDlg;
		m_cChangeProjectDlg = nullptr;
	}
	if (m_cChangeProjectDlg == nullptr)
	{
		m_cChangeProjectDlg = new CChangeProject;
		m_cChangeProjectDlg->Create(IDD_DIALOG_CHANGE_PROJECT, this);
	}
	m_cChangeProjectDlg->ShowWindow(SW_SHOW);
}


void CProjectAADlg::OnBnClickedButtonStart()
{
	gSystemMgr.m_bStopCapture = 0;
	CWnd* pBtn = nullptr;
	pBtn = (CWnd*)GetDlgItem(IDC_BUTTON_START);
	pBtn->EnableWindow(FALSE);
}


void CProjectAADlg::OnBnClickedButtonStop()
{
	gSystemMgr.m_bStopCapture = 1;
	gSystemMgr.imgCap->m_bInitFlag = FALSE;
	CWnd* pBtn = nullptr;
	pBtn = (CWnd*)GetDlgItem(IDC_BUTTON_START);
	pBtn->EnableWindow(TRUE);
}


void CProjectAADlg::OnOpenCaptureDlg()
{
	if (m_cCaptureDlg != nullptr)
	{
		delete m_cCaptureDlg;
		m_cCaptureDlg = nullptr;
	}
	if (m_cCaptureDlg == nullptr)
	{
		m_cCaptureDlg = new CImageCaptureDlg;
		m_cCaptureDlg->Create(IDD_DIALOG_CAPTURE, this);
	}
	m_cCaptureDlg->ShowWindow(SW_SHOW);
}


void CProjectAADlg::OnOpenSFRDlg()
{
	if (m_cSfrSettingDlg != nullptr)
	{
		delete m_cSfrSettingDlg;
		m_cSfrSettingDlg = nullptr;
	}
	if (m_cSfrSettingDlg == nullptr)
	{
		m_cSfrSettingDlg = new CSFRSettingDlg;
		m_cSfrSettingDlg->Create(IDD_DIALOG_SFR, this);
	}
	m_cSfrSettingDlg->ShowWindow(SW_SHOW);
}

void CProjectAADlg::Repaint(CWnd* pWnd, int last_Width, int now_Width, int last_Height, int now_Height, int cnt)
{
	if (pWnd)
	{
		CRect rect;
		CRect rect2;
		pWnd->GetWindowRect(&rect2);
		rect = OriRect[cnt];
		int n = 62;
		int m = 8;
		//rect2.top = rect2.top - n;
		//rect2.bottom = rect2.bottom - n;
		ScreenToClient(&rect2);

		double proportion_x = now_Width / (double)last_Width;
		double proportion_y = now_Height / (double)last_Height;

		rect.left = (long)(rect.left * proportion_x + 0.5 - m * proportion_x);
		rect.right = (long)(rect.left + RectW[cnt] * proportion_x + 0.5);
		rect.top = (long)(rect.top * proportion_y + 0.5 - n * proportion_y);
		rect.bottom = (long)(rect.top + RectH[cnt] * proportion_y + 0.5);
		pWnd->MoveWindow(&rect);
	}

}

void CProjectAADlg::OnSize(UINT nType, int cx, int cy)
{
	CDialogEx::OnSize(nType, cx, cy);

	if (nType == SIZE_RESTORED || nType == SIZE_MAXIMIZED)//窗体大小发生变动。处理程序
	{
		float fsp[2];
		POINT Newp; //获取现在对话框的大小
		CRect recta;
		GetClientRect(&recta); //取客户区大小   
		Newp.x = recta.right - recta.left;
		Newp.y = recta.bottom - recta.top;
		fsp[0] = (float)Newp.x / Old.x;
		fsp[1] = (float)Newp.y / Old.y;
		CRect Rect;
		int woc;
		CPoint OldTLPoint, TLPoint; //左上角
		CPoint OldBRPoint, BRPoint; //右下角
		HWND hwndChild = ::GetWindow(m_hWnd, GW_CHILD); //列出所有控件   
		while (hwndChild)
		{
			woc = ::GetDlgCtrlID(hwndChild);//取得ID
			GetDlgItem(woc)->GetWindowRect(Rect);
			ScreenToClient(Rect);
			OldTLPoint = Rect.TopLeft();
			TLPoint.x = long(OldTLPoint.x * fsp[0]);
			TLPoint.y = long(OldTLPoint.y * fsp[1]);
			OldBRPoint = Rect.BottomRight();
			BRPoint.x = long(OldBRPoint.x * fsp[0]);
			BRPoint.y = long(OldBRPoint.y * fsp[1]); //高度不可读的控件（如:combBox),不要改变此值.
			Rect.SetRect(TLPoint, BRPoint);
			GetDlgItem(woc)->MoveWindow(Rect, TRUE);
			hwndChild = ::GetWindow(hwndChild, GW_HWNDNEXT);
		}
		Old = Newp;
	}
	Invalidate();//更新窗口

	//if (0 == m_rcUiRect.left && 0 == m_rcUiRect.right && 0 == m_rcUiRect.top && 0 == m_rcUiRect.bottom)//第一次启动对话框时的大小变化不做处理
	//{
	//}
	//else
	//{
	//	if (0 == cx && 0 == cy)//如果是按下了最小化，则触发条件，这时不保存对话框数据
	//	{
	//		return;
	//	}
	//	CRect rectDlgChangeSize;
	//	GetClientRect(&rectDlgChangeSize);//存储对话框大小改变后对话框大小数据
	//	//if (rectDlgChangeSize.Width() > 400 && rectDlgChangeSize.Height() > 200) {
	//	CWnd *pWnd;
	//	pWnd = GetDlgItem(IDC_DISPLAY);
	//	Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), 0);
	//	pWnd = GetDlgItem(IDC_SFR_CURVE);
	//	Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), 1);
	//	pWnd = GetDlgItem(IDC_BUTTON_START);
	//	Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), 2);
	//	pWnd = GetDlgItem(IDC_BUTTON_STOP);
	//	Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), 3);
	//	pWnd = GetDlgItem(IDC_BUTTON1);
	//	Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), 4);
	//	pWnd = GetDlgItem(IDC_AA_CURVE); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), 5);
	//	pWnd = GetDlgItem(IDC_CHECK1); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), 6);
	//	pWnd = GetDlgItem(IDC_CHECK2); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), 7);
	//	int n = 7;
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_1); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_2); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_3); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_4); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_5); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_6); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_7); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_8); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_9); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_10); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_11); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_12); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_13); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_14); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_15); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_16); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_17); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_18); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_19); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_20); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_21); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_22); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_23); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_24); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_25); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_26); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_27); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_28); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_29); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_30); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_31); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_32); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_33); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_34); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_35); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_36); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_37); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_38); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_39); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_40); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_41); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_42); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_43); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_44); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_45); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_46); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_47); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_48); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_49); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_50); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_51); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_52); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_53); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_54); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_55); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_56); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_57); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_58); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_59); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_60); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_61); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_62); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_63); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_64); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_65); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_66); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_67); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_68); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_69); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_70); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_71); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_72); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_73); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_74); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_75); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_76); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_77); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_78); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_79); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_80); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_81); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_82); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_83); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_84); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_85); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_86); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_87); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_88); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_89); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_90); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_91); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_92); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_93); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_94); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_95); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_96); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	//n = n + 1; pWnd = GetDlgItem(IDC_STATIC_97); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_99); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_STATIC_101); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
//
	//	n = n + 1; pWnd = GetDlgItem(IDC_BUTTON_SAVE); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_BUTTON_HOME_40); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_BUTTON_HOME_41); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_BUTTON_CLEAR1); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_BUTTON_CLAER2); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_BUTTON2); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_BUTTON3); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
	//	n = n + 1; pWnd = GetDlgItem(IDC_BUTTON4); Repaint(pWnd, m_rcUiRect.Width(), rectDlgChangeSize.Width(), m_rcUiRect.Height(), rectDlgChangeSize.Height(), n);
//
	//}
	////GetClientRect(&m_rcUiRect); //save size of dialog
	//Invalidate();//更新窗口
}


void CProjectAADlg::OnOpenTcpipDlg()
{
	if (m_cTcpipDlg != nullptr)
	{
		delete m_cTcpipDlg;
		m_cTcpipDlg = nullptr;
	}
	if (m_cTcpipDlg == nullptr)
	{
		m_cTcpipDlg = new CTcpipDlg;
		m_cTcpipDlg->Create(IDD_DIALOG_TCPIP, this);
	}
	m_cTcpipDlg->ShowWindow(SW_SHOW);
}

void CProjectAADlg::OnOpenIODlg()
{
	if (m_cIODlg != nullptr)
	{
		delete m_cIODlg;
		m_cIODlg = nullptr;
	}
	if (m_cIODlg == nullptr)
	{
		m_cIODlg = new CIOControlDlg;
		m_cIODlg->Create(IDD_DIALOG1_IO, this);
	}
	m_cIODlg->ShowWindow(SW_SHOW);
}

void CProjectAADlg::OnCancel()
{
	gSystemMgr.m_nExitFlag = 1;

	gSystemMgr.m_bStopCapture = 1;
	gSystemMgr.imgCap->m_bInitFlag = FALSE;
	Sleep(200);

	//还要加停止所有轴，锁紧刹车

	gSystemMgr.m_cSocketServer.CloseSocketServer();
	KillTimer(TIMER_ID_IO_CONTROL_STATUS);
	dmc_emg_stop(gSystemMgr.m_nCard);

	dmc_board_close();
	delete m_cAADlg;
	delete m_cMotorDlg;
	delete m_cLogDlg;
	delete m_cChangeProjectDlg;
	delete m_cCaptureDlg;
	delete m_cSfrSettingDlg;
	delete m_cTcpipDlg;
	delete m_cIODlg;
	delete m_cManualDlg;
	delete m_cRS232Dlg;
	delete m_cLoginDlg;

	gSystemMgr.imgFile.release();
	gSystemMgr.imgCTS.release();
	gSystemMgr.imgRLG.release();

	gSystemMgr.m_cClientGlue.CloseClient();

	//HANDLE hself = GetCurrentProcess();
	//TerminateProcess(hself, 0); 
	CDialogEx::OnCancel();
}

LRESULT CProjectAADlg::OnReceiveServerMsg(WPARAM wParam, LPARAM lParam)
{
	CString cstrp = (BSTR)wParam;
	SysFreeString((BSTR)wParam);

	gSystemLog.DisplayLogAndSave(cstrp.GetBuffer(), LV_EVENT);

	std::vector<wstring> vResultItem = _utils::SplitString(cstrp.GetBuffer(), L";");

	//gSystemLog.DisplayLogAndSave(cstrp.GetBuffer(), LV_EVENT);

	//在此处添加对接收数据的分析

	return LRESULT();
}


void CProjectAADlg::OnBnClickedCheck1()
{
	CString cstr;
	CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK1);
	int nFlag = pCheckBox->GetCheck();
	if (nFlag == BST_CHECKED)
	{
		gSystemMgr.m_bAutoFlag_Glue = 1;
		cstr.Append(L"开启检胶自动");
		gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
		GetDlgItem(IDC_CHECK1)->SetWindowTextW(L"检胶");
	}
	if (nFlag == BST_UNCHECKED)
	{
		gSystemMgr.m_bAutoFlag_Glue = 0;
		cstr.Append(L"关闭检胶自动");
		gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
		GetDlgItem(IDC_CHECK1)->SetWindowTextW(L"检胶");
	}
}


void CProjectAADlg::OnBnClickedCheck2()
{
	CString cstr;
	CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK2);
	int nFlag = pCheckBox->GetCheck();
	if (nFlag == BST_CHECKED)
	{
		gSystemMgr.m_bAutoAAFlag = 1;
		cstr.Append(L"开启AA自动");
		gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
		GetDlgItem(IDC_CHECK2)->SetWindowTextW(L"AA");
	}
	if (nFlag == BST_UNCHECKED)
	{
		gSystemMgr.m_bAutoAAFlag = 0;
		cstr.Append(L"关闭AA自动");
		gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
		GetDlgItem(IDC_CHECK2)->SetWindowTextW(L"AA");
	}
}


HBRUSH CProjectAADlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr1 = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);

	DeleteObject(hbr);

	UINT id = pWnd->GetDlgCtrlID();
	CString Cstr;
	if (id == IDC_CHECK1)
	{
		if (gSystemMgr.m_bAutoFlag_Glue)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
			pDC->SetTextColor(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
			pDC->SetTextColor(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_CHECK2)
	{
		if (gSystemMgr.m_bAutoAAFlag)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
			pDC->SetTextColor(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
			pDC->SetTextColor(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_1 || id == IDC_STATIC_2 || id == IDC_STATIC_50 || id == IDC_STATIC_51 || id == IDC_STATIC_54
		|| id == IDC_STATIC_56 || id == IDC_STATIC_58 || id == IDC_STATIC_60 || id == IDC_STATIC_69 || id == IDC_STATIC_71 || id == IDC_STATIC_72
		|| id == IDC_STATIC_74 || id == IDC_STATIC_76 || id == IDC_STATIC_53 || id == IDC_STATIC_92 || id == IDC_STATIC_93)
	{
		hbr = CreateSolidBrush(RGB(169, 179, 195));
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_3 || id == IDC_STATIC_20)
	{
		GetDlgItem(id)->GetWindowTextW(Cstr);
		if (Cstr == L"Testing")
		{
			hbr = CreateSolidBrush(RGB(222, 233, 20));
		}
		else if (Cstr == L"Pass")
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else if (Cstr == L"Fail")
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(70, 111, 166));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_19 || id == IDC_STATIC_42)
	{
		GetDlgItem(id)->GetWindowTextW(Cstr);
		if (Cstr == L"...")
		{
			hbr = CreateSolidBrush(RGB(157, 187, 210));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_5 || id == IDC_STATIC_8 || id == IDC_STATIC_14 || id == IDC_STATIC_17
		|| id == IDC_STATIC_22 || id == IDC_STATIC_25 || id == IDC_STATIC_28 || id == IDC_STATIC_31 || id == IDC_STATIC_34
		|| id == IDC_STATIC_37 || id == IDC_STATIC_40)
	{
		GetDlgItem(id)->GetWindowTextW(Cstr);
		if (Cstr == L"OK")
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else if (Cstr == L"NG")
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(222, 233, 20));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_10 || id == IDC_STATIC_11)
	{
		GetDlgItem(id)->GetWindowTextW(Cstr);
		if (Cstr == L"...")
		{
			hbr = CreateSolidBrush(RGB(222, 233, 20));
		}
		else
		{
			double val = _ttof(Cstr);
			if (val < gSystemMgr.glueWidthUp && val > gSystemMgr.glueWidthLow)
			{
				hbr = CreateSolidBrush(RGB(0, 255, 0));
			}
			else
			{
				hbr = CreateSolidBrush(RGB(255, 0, 0));
			}
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_43)
	{
		if (gSystemMgr.Com1ConnectFlag)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_45)
	{
		if (gSystemMgr.m_nPassRfidFlag)
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_44)
	{
		if (gSystemMgr.Com2ConnectFlag)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_46)
	{
		if (gSystemMgr.m_cClientGlue.m_bConnect)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_47)
	{
		if (gSystemMgr.m_bHomeFlag)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_48)
	{
		if (!gSystemMgr.m_bMotorErrorFlag)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_49)
	{
		if (!gSystemMgr.m_bEmergencyStopFlag)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_94)
	{
		if (gSystemMgr.m_nPowerLinked == TRUE)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_84)
	{
		if (gSystemMgr.SfrAvgValue[0] > gSystemMgr.m_dSpecSfr[0]/*gSystemMgr.SfrResult[0][0] == TRUE*/)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_86)
	{
		if (gSystemMgr.SfrAvgValue[1] > gSystemMgr.m_dSpecSfr[1]/*gSystemMgr.SfrResult[1][0] == TRUE*/)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_96)
	{
		if (gSystemMgr.SfrAvgValue[2] > gSystemMgr.m_dSpecSfr[1]/*gSystemMgr.SfrResult[2][0] == TRUE*/)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_99)
	{
		if (gSystemMgr.SfrAvgValue[3] > gSystemMgr.m_dSpecSfr[1]/*gSystemMgr.SfrResult[3][0] == TRUE*/)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_101)
	{
		if (gSystemMgr.SfrAvgValue[4] > gSystemMgr.m_dSpecSfr[1]/*gSystemMgr.SfrResult[4][0] == TRUE*/)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_78 || id == IDC_STATIC_80)
	{
		if (gSystemMgr.CenterTestResult == TRUE)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_82 || id == IDC_STATIC_63)
	{
		if (gSystemMgr.TiltTestResult == TRUE)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else
	{
		hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	}
	hbr1 = hbr;
	return hbr1;
}

void CProjectAADlg::OnOpenAADlg()
{
	if (m_cAADlg != nullptr)
	{
		delete m_cAADlg;
		m_cAADlg = nullptr;
	}
	if (m_cAADlg == nullptr)
	{
		m_cAADlg = new CAAControlDlg;
		m_cAADlg->Create(IDD_DIALOG_AA, this);
	}
	m_cAADlg->ShowWindow(SW_SHOW);
}

void CProjectAADlg::OnBnClickedButtonHome40()
{
	gSystemMgr.m_nButtonValue = 10;
}


void CProjectAADlg::OnOpenManualControl()
{
	if (m_cManualDlg != nullptr)
	{
		delete m_cManualDlg;
		m_cManualDlg = nullptr;
	}
	if (m_cManualDlg == nullptr)
	{
		m_cManualDlg = new CManualControlDlg;
		m_cManualDlg->Create(IDD_DIALOG_CONTROL, this);
	}
	m_cManualDlg->ShowWindow(SW_SHOW);
}


void CProjectAADlg::OnOpenComDlg()
{
	if (m_cRS232Dlg != nullptr)
	{
		delete m_cRS232Dlg;
		m_cRS232Dlg = nullptr;
	}
	if (m_cRS232Dlg == nullptr)
	{
		m_cRS232Dlg = new CRS232SetDlg;
		m_cRS232Dlg->Create(IDD_DIALOG_COM, this);
	}
	m_cRS232Dlg->ShowWindow(SW_SHOW);
}


void CProjectAADlg::OnOpenLogin()
{
	if (m_cLoginDlg != nullptr)
	{
		m_cLoginDlg->ShowWindow(SW_SHOW);
	}
	if (m_cLoginDlg == nullptr)
	{
		m_cLoginDlg = new CLoginDlg;
		m_cLoginDlg->Create(IDD_DIALOG_LOGIN, this);
	}
	m_cLoginDlg->ShowWindow(SW_SHOW);
}


void CProjectAADlg::OnBnClickedButtonSave()
{
	gSystemMgr.SaveTestReport2(gSystemMgr.imgCap->bBmpTestBuf, gSystemMgr.imgCap->iBmpW, gSystemMgr.imgCap->iBmpH, 0);
}


void CProjectAADlg::OnBnClickedButtonClear1()
{
	if (IDYES == AfxMessageBox(L"确定清空白场测试站统计数据吗？", MB_YESNO))
	{
		//	CString cstr;
		//	cstr.Format(L"白场旧数据: %d,%d,%d,%d,%.2f,%d,%d", gSystemMgr.m_nWhiteAll, gSystemMgr.m_nWhiteOK, gSystemMgr.m_nWhiteNG, gSystemMgr.m_nWhitePass
		//		, gSystemMgr.m_dWhiteTime_S, gSystemMgr.m_nWhiteTime_M, gSystemMgr.m_nWhiteTime_H);
		//	gSystemMgr.m_nWhiteAll = 0;
		//	gSystemMgr.m_nWhiteOK = 0;
		//	gSystemMgr.m_nWhiteNG = 0;
		//	gSystemMgr.m_nWhitePass = 0;
		//	gSystemLog.DisplayLogAndSave(L"白场测试站统计数据清除成功。", LV_ERROR);
	}
}


void CProjectAADlg::OnBnClickedButtonClaer2()
{
	if (IDYES == AfxMessageBox(L"确定清空 AA 站统计数据吗？", MB_YESNO))
	{
		CString cstr;
		cstr.Format(L"AA旧数据: %d,%d,%d,%d,%d", gSystemMgr.m_nAAAll, gSystemMgr.m_nAAOK, gSystemMgr.m_nAANG1, gSystemMgr.m_nAANG2, gSystemMgr.m_nAANG3);
		gSystemMgr.m_nAAAll = 0;
		gSystemMgr.m_nAAOK = 0;
		gSystemMgr.m_nAANG1 = 0;
		gSystemMgr.m_nAANG2 = 0;
		gSystemMgr.m_nAANG3 = 0;
		gSystemLog.DisplayLogAndSave(L"AA 站统计数据清除成功。", LV_ERROR);
	}
}



void CProjectAADlg::OnBnClickedButton2()
{
	gSystemMgr.m_nButtonValue = 26;
}


void CProjectAADlg::OnBnClickedButtonHome41()
{
	gSystemMgr.imgCTS.write_iic_center();
	gSystemLog.DisplayLogAndSave(L"写入 iic 完成", LV_EVENT);
}


BOOL CProjectAADlg::PreTranslateMessage(MSG* pMsg)
{
	if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_SPACE) return TRUE; //如果是空格消息，返回；
	if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE) return TRUE; //如果是Esc消息，返回；
	if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN) return TRUE;

	return CDialogEx::PreTranslateMessage(pMsg);
}


void CProjectAADlg::OnBnClickedButton3()
{
	gSystemMgr.m_nButtonValue = 27;
}


void CProjectAADlg::OnBnClickedButton4()
{
	if (gSystemMgr.m_nPassRfidFlag) {
		if (IDYES == AfxMessageBox(L"确定 开启RFID 吗？", MB_YESNO | MB_ICONWARNING))
		{
			gSystemMgr.m_nPassRfidFlag = 0;
		}
	}
	else {
		if (IDYES == AfxMessageBox(L"确定 屏蔽RFID 吗？", MB_YESNO | MB_ICONWARNING))
		{
			gSystemMgr.m_nPassRfidFlag = 1;
		}
	}
}

void CProjectAADlg::OnBnClickedButtonResetTz()
{
	gSystemMgr.TanzhenUse = 0;
	gSystemMgr.m_cGeneralSetting.SaveConfigIni(L"GeneralSetting", L"AATanZhen", L"0");
}

void CProjectAADlg::OnBnClickedButton5()
{
	SetDlgItemTextW(IDC_STATIC_8, L"...");
	SetDlgItemTextW(IDC_STATIC_10, L"...");
	SetDlgItemTextW(IDC_STATIC_11, L"...");

	gSystemMgr.m_cClientGlue.m_sendBuffer.push_front(L"Trigger");

}
